const network = {
  getList: function(params,netUrl){
    wx.request({
      url: netUrl,
      success:function(res){
        var list = res.data.subject_collection_items;
        if(params &&　params.success){
          params.success(list);
        }
      }
    })
  },
  getDetail: function(params,netUrl){
    wx.request({
      url: netUrl,
      success:function(res){
        var list = res.data;
        if(params &&　params.success){
          params.success(list);
        }
      }
    })
  },
  getTags:function(params){
    var type = params.type;
    var id = params.id;
    var netUrl = "https://m.douban.com/rexxar/api/v2/tv/"+id+"/tags?count=8"
    wx.request({
      url: netUrl,
      success:function(res){
        var tags = res.data.tags;
        if(params &&　params.success){
          params.success(tags);
        }
      }
    })
  },

  commentUrl:function(id,start=0,count=3){
    return 'https://m.douban.com/rexxar/api/v2/tv/' + id + '/interests?count=' + count + '&start=' + start;
  },

  getComment:function(params){
    var id = params.id;
    var start = params.start?params.start:0;
    var count = params.count?params.count:3;
    var netUrl = this.commentUrl(id,start,count);
    wx.request({
      url: netUrl,
      success:function(res){
        var comment = res.data;
        if(params &&　params.success){
          params.success(comment);
        }
        // console.log(res);
      }
    })
  },

  searchUrl: function (q) {
    return "https://m.douban.com/rexxar/api/v2/search?type=movie&q=" + q
  },

  getSearch: function(params){
    var q = params.q;
    var url = this.searchUrl(q);
    wx.request({
      url: url,
      success:function(res){
        var subjects = res.data.subjects;
        if (params.success) {
          params.success(subjects);
        }
      }
      // fail:function(res){
      //   var subjects = "";
      //   if (params.success) {
      //     params.success(subjects);
      //   }
      // }
    })
  }
}

export {network}